//
//  UIButton+extension.swift
//  weibo
//
//  Created by Qing on 2017/5/1.
//  Copyright © 2017年 成哥哥. All rights reserved.
//

import UIKit

///便利构造
extension UIButton {
    
    
    /// 便利构造Button
    ///
    /// - Parameters:
    ///   - imageName: 图像名称
    ///   - backImageName: 背影图名称
    convenience init(imageName: String, backImageName: String){
    
        self.init()
        
        setImage(UIImage(named: imageName), for: .normal)
        setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
        
        setBackgroundImage(UIImage(named: backImageName), for: .normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), for: .highlighted)
        
        //会根据图片大小自动调整尺寸
        sizeToFit()
        
    }

    
    /// 便利构造Button
    ///
    /// - Parameters:
    ///   - type: 类型
    ///   - backImage: 背景图片名称
    ///   - title: 显示文字
    ///   - titelColors: 文字颜色
    ///   - stated: 背景图、文字、文字颜色 状态
    convenience init(type: UIButtonType, image: String, title: String, stated: UIControlState) {
    
        self.init()
        
        UIButton(type: type)
//        setBackgroundImage(UIImage(named: backImage ), for: stated)
        setImage(UIImage(named: image), for: UIControlState.normal)
        setTitle(title, for: stated)
        setTitleColor(UIColor.orange, for: .normal)
        titleLabel?.font = UIFont.boldSystemFont(ofSize: 12)
        
        
        
        
//        setTitleColor(titelColors, for: stated)
        
//        fileprivate lazy var registered: UIButton = {
//            
//            let btn = UIButton(type: UIButtonType.custom)
//            btn.setBackgroundImage(UIImage(named: "visitor_icon_loginButton_image"), for: UIControlState.normal)
//            btn.setTitle("注册", for: UIControlState.normal)
//            btn.setTitleColor(UIColor.black, for: UIControlState.normal)
//            return btn
//            
//        }()
    }
    
    
}
